#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int NN=5e5+4;
int l[NN],r[NN];
int main()
{
    freopen("study.in","r",stdin);
    freopen("study.out","w",stdout);
    int n,q;
    scanf("%d%d",&n,&q);
    for(int i=1;i<n;i++)
        scanf("%d%d",&l[i],&r[i]);
    while(q--)
    {
        int opt;
        scanf("%d",&opt);
        if(opt==1)
        {
            int p,s,e;
            scanf("%d%d%d",&p,&s,&e);
            l[p]=s,r[p]=e;
        }
        else
        {
            int a,b,c,d;
            scanf("%d%d%d%d",&a,&b,&c,&d);
            ll res=0;
            if(a<=c)
                for(int i=a;i<c;i++)
                {
                    b=max(b,l[i]);
                    if(b>=r[i])
                    {
                        res+=b-r[i]+1;
                        b=r[i]-1;
                    }
                    b++;
                }
            else
                for(int i=a-1;i>=c;i--)
                {
                    b=max(b,l[i]);
                    if(b>=r[i])
                    {
                        res+=b-r[i]+1;
                        b=r[i]-1;
                    }
                    b++;
                }
            res+=max(0,b-d);
            printf("%lld\n",res);
        }
    }
    return 0;
}